<?php
namespace Rainrock\Framework\Model;


use Rainrock\Framework\kernel\core\Model;
use Rainrock\Framework\kernel\base\Rock;
use Rainrock\Framework\kernel\base\Request;
use Rainrock\Framework\kernel\base\Web;
use Rainrock\Framework\kernel\core\Module;
use Rainrock\Framework\kernel\base\Auth;

class syslogModel extends Model{
	
	public function isInstall()
	{
		$mode 			 = Module::get('syslog','system');
		if(!$mode)return false;
		return $mode;
	}
	
	public function add($type, $remark, $param=array())
	{
		$mode 			 = $this->isInstall();
		if(!$mode)return false;
		$iarr['type'] 	 	= $type;
		$iarr['remark'] 	= $remark;
		$iarr['optdt']  	= Rock::now();
		$iarr['ip'] 		= Request::getIp();
		$iarr['web'] 	 	= Request::web();
		if(!isset($param['device']))$iarr['device'] 	= Request::get('device');
		$iarr['url'] 	 	= Rock::nowurl();
		if(!isset($param['optid'])){
			$iarr['optid'] 		= Auth::$USERID;
			$iarr['optname'] 	= Auth::$NAME;
		}
		foreach($param as $k=>$v)$iarr[$k] = $v;
		return $this->insert($iarr);
	}
	
	public function addQueue($type, $remark, $param=array())
	{
		$param['level'] = 2;
		return $this->add($type, $remark, $param);
	}
	
	public function addError($type, $remark, $param=array())
	{
		$param['level'] = 3;
		return $this->add($type, $remark, $param);
	}
	
	public function addFile($type, $remark, $param=array())
	{
		$param['level'] = 4;
		$path 	= Rock::createLog($remark,'syslog');
		return $this->add($type, $path, $param);
	}
}